package com.atstudent.gmall.web.controller;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.product.vo.CategoryVo;
import com.atstudent.gmall.common.feign.product.BaseCategoryFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 前端也看-首页
 * @Author 薛有朋
 * @CreatDate 2024/11/28 17:04
 **/
@Controller
public class IndexController {
    @Autowired
    private BaseCategoryFeignClient baseCategoryFeignClient;

    @GetMapping(value = {"/", "/index.html"})
    public String index(Model model){

        //从feign里面拿到数据
        Result<List<CategoryVo>> allCategoryTree = baseCategoryFeignClient.findAllCategoryTree();

        //查询到的结果封装到model数据模型中
        List<CategoryVo> categoryVoList = allCategoryTree.getData();
        model.addAttribute("list" , categoryVoList);

        return "index/index";
    }
}
